package com.droidclaimcustomer.bl;

import android.content.Context;

import com.droidclaimcustomer.dal.ClaimInfoDal;
import com.droidclaimcustomer.dal.DatabaseLoader;
import com.droidclaimcustomer.helper.asyntask.ICompleteListener;
import com.droidclaimcustomer.model.ClaimInfoModel;

public class CustomerBl {
	ICompleteListener listener;
	

	public CustomerBl(ICompleteListener listener) {
		this.listener = listener;
	}

	public String GetAllClaimInfo(String licensePlateNo) {
		DatabaseLoader<ClaimInfoModel, String> dbLoader = new DatabaseLoader<ClaimInfoModel, String>(
				(Context) listener, null);
		String claimInfoTask = ClaimInfoDal.GetAllClaimInfoId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(licensePlateNo);
		
		return claimInfoTask;
	}
	
	public String GetLastClaimInfo(String licensePlateNo) {
		DatabaseLoader<ClaimInfoModel, String> dbLoader = new DatabaseLoader<ClaimInfoModel, String>(
				(Context) listener, "GetLastClaimInfo");
		String claimInfoTask = ClaimInfoDal.GetLastClaimInfoId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(licensePlateNo);
		
		return claimInfoTask;
	}
	
	public String GetClaimInfoByClaimId(long claimId) {
		DatabaseLoader<ClaimInfoModel, String> dbLoader = new DatabaseLoader<ClaimInfoModel, String>(
				(Context) listener, "GetClaimInfoByClaimId");
		String claimInfoTask = ClaimInfoDal.GetClaimInfoByClaimId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(Long.toString(claimId));
		
		return claimInfoTask;
	}
	
	public String GetClaimInfoByRowId(long rowId) {
		DatabaseLoader<ClaimInfoModel, String> dbLoader = new DatabaseLoader<ClaimInfoModel, String>(
				(Context) listener, "GetClaimInfoByRowId");
		String claimInfoTask = ClaimInfoDal.GetClaimInfoByRowId;
		dbLoader.setTaskCompletionListener(listener);
		dbLoader.setTaskId(claimInfoTask);
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dbLoader.setDAL(dal);
		dbLoader.execute(Long.toString(rowId));
		
		return claimInfoTask;
	}

	public long addClaimInfo(ClaimInfoModel data) {
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dal.open();
		long result = dal.add(data);
		dal.close();
		
		return result;
	}

	public boolean updateClaiminfo(long rowIndex, ClaimInfoModel data) {
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dal.open();
		boolean result = dal.update(rowIndex,data);
		dal.close();
		return result;
	}

	public boolean removeClaimInfo(long claimId) {		
		ClaimInfoDal dal = new ClaimInfoDal((Context)listener);
		dal.open();
		boolean result =  dal.remove(claimId);
		dal.close();
		return result;
	}
}
